package com.yuguoxy.mytomcat;

import java.io.IOException;
import java.io.OutputStream;

public class YGHttpResponse {
    private OutputStream outputStream;

    public YGHttpResponse(OutputStream outputStream) {
        this.outputStream = outputStream;
    }

    public void write(String content) throws IOException {
        StringBuilder sb = new StringBuilder();
        sb.append("HTTP/1.1 200 OK\n"); //响应行
        sb.append("Content-Type:text/html;charset=utf-8\n");
        sb.append("\r\n");
        sb.append("<html><body>");
        sb.append(content);
        sb.append("</body></html>");
        System.out.println(sb.toString());
        this.outputStream.write(sb.toString().getBytes());
        this.outputStream.close();
    }
}
